

-- skill functions

local STARTSKILL = 24

local pm = FindMetaTable("Player") 

	function plySkillSpawn( ply )
		ply:Skills_Create()
	end
	
	hook.Add("PlayerInitialSpawn", "SkillSystemStart", plySkillSpawn)
	
	
	function pm:Skills_Create()
  	 if self:GetPData("hasskills") == nil then
   	 print("Setting up skills for: "..self:Name()..".")
	 self:SetPData("hasskills",1)
	
   	 self:SetPData("mining", STARTSKILL)
	 self:SetPData("refining", STARTSKILL) --Vl4dmir added "refining" skill and updated accordingly
	 self:SetPData("smelting",1)
	 
	 self:SetNWInt("mining", STARTSKILL)
	 self:SetNWInt("refining", STARTSKILL) --Vl4dmir added "refining" skill and updated accordingly
	 self:SetNWInt("smelting",1)
    else
		print("Updating: "..self:Name().."'s skills.")
	self:SetNWInt("mining", tonumber(self:GetPData("mining")))
	self:SetNWInt("refining", tonumber(self:GetPData("refining")))
	self:SetNWInt("smelting", tonumber(self:GetPData("smelting")))
	
   end
end
function pm:Skill_Set( kind , value) 
	--if kind == "mining" or "refining" or "smelting" or "skill4" then
		self:SetPData(tostring(kind), tonumber(value) ) 
		self:SetNWInt(tostring(kind), tonumber(value) ) 
	--end
end

function pm:Skill_Add( kind , value ) 
	
		
			local current = tonumber(self:GetPData(kind)) 			
			self:Skill_Set( kind ,current + value ) 	
		
		
end

function pm:Skill_Has( kind ) 
	 --if kind == "mining" or "refining" or "smelting" or "skill4" then
		local current = tonumber(self:GetPData( tostring(kind) )) 		
		if current >= 1 then 
			return true 
		else
			return false 
		end
	--end
end

function pm:Skill_Get( kind ) 
	--if kind == "mining" or "refining" or "smelting" or "skill4" then
		local current = tonumber(self:GetPData( tostring(kind) )) 
		return current
	--end
end

function pm:Skill_Take( kind , value )  
	--if kind == "mining" or "refining" or "smelting" or "skill4" then
		if self:Skill_Has( tostring(kind) ) then 
			local current = tonumber(self:GetPData( tostring(kind) )) 
			self:Skill_Set( tostring(kind), current - value ) 
		end
	--end
end
